package com.ruoyi.web.admin.controller.system;

import java.util.List;

import com.ruoyi.system.domain.Area;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;

/**
 * 区域信息操作处理
 *
 * @author ruoyi
 */
@Api(tags = "区域管理")
@RestController
@RequestMapping("/system/area")
public class AreaController extends BaseController {

    private final IAreaService areaService;

    public AreaController(IAreaService areaService) {
        this.areaService = areaService;
    }

    /**
     * 获取区域列表
     */
    @ApiOperation(value = "获取区域列表", notes = "获取所有区域信息")
    @PreAuthorize("@ss.hasPermi('system:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(Area area) {
        startPage();
        List<Area> list = areaService.selectAreaList(area);
        return getDataTable(list);
    }

    /**
     * 根据区域编号获取详细信息
     */
    @ApiOperation(value = "获取区域详细信息", notes = "根据id获取区域详细信息")
    @ApiImplicitParam(name = "id", value = "区域ID", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermi('system:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(areaService.selectAreaById(id));
    }

    /**
     * 新增区域
     */
    @ApiOperation(value = "新增区域", notes = "新增区域信息")
    @PreAuthorize("@ss.hasPermi('system:area:add')")
    @Log(title = "区域管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Area area) {
        return toAjax(areaService.insertArea(area));
    }

    /**
     * 修改区域
     */
    @ApiOperation(value = "修改区域", notes = "修改区域信息")
    @PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "区域管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Area area) {
        return toAjax(areaService.updateArea(area));
    }

    /**
     * 删除区域
     */
    @ApiOperation(value = "批量删除区域", notes = "批量删除区域信息")
    @ApiImplicitParam(name = "ids", value = "区域ID数组", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long[].class)
    @PreAuthorize("@ss.hasPermi('system:area:remove')")
    @Log(title = "区域管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(areaService.deleteAreaByIds(ids));
    }

    /**
     * 删除单个区域
     */
    @ApiOperation(value = "删除单个区域", notes = "删除单个区域信息")
    @ApiImplicitParam(name = "id", value = "区域ID", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermi('system:area:remove')")
    @Log(title = "区域管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(areaService.deleteAreaById(id));
    }
}